"""mxshop URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/3.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.conf.urls import url
# from django.contrib import admin
from django.urls import path, re_path, include
from rest_framework.authtoken import views
from rest_framework_simplejwt.views import (
    TokenObtainPairView,
    TokenRefreshView,
)
from mxshop.settings import MEDIA_ROOT
from django.views.static import serve
from rest_framework.documentation import include_docs_urls
from rest_framework.routers import DefaultRouter
from goods.views import GoodsListViewSet, GoodsCategoryListViewSet, \
       BannerViewSet, IndexCategoryViewSet
from trade.views import ShoppingCartViewSet, OrderViewSet, AlipayView
from users.views import SmsCodeViewSet, UserViewSet, MyObtainTokenPairView
from user_operation.views import UserFavViewSet, LeaveMessageView, \
       AddressViewSet

# Create a router and register our viewsets with it.
router = DefaultRouter()
router.register(r'goods', GoodsListViewSet, basename="goods")
router.register(r'categories', GoodsCategoryListViewSet, basename="category-list")
router.register(r'codes', SmsCodeViewSet, basename="smscode")
router.register(r'users', UserViewSet, basename="user-register")
router.register(r'userfavs', UserFavViewSet, basename="user-favs")
router.register(r'messages', LeaveMessageView, basename="messages")
router.register(r'address', AddressViewSet, basename="address")
router.register(r'shopcarts', ShoppingCartViewSet, basename="shopcarts")
router.register(r'orders', OrderViewSet, basename="orders")
router.register(r'banners', BannerViewSet, basename="banners")
router.register(r'indexgoods', IndexCategoryViewSet, basename="indexgoods")

# goods_list = GoodsListViewSet.as_view({
#     'get': 'list',
# })
import xadmin
from django.views.generic import TemplateView

urlpatterns = [
       path('xadmin/', xadmin.site.urls),
       re_path('media/(?P<path>.*)$', serve, {"document_root": MEDIA_ROOT}),
       url(r'^docs/', include_docs_urls(title='candy')),
       path('api-auth/', include('rest_framework.urls')),
       path('api-token-auth/', views.obtain_auth_token),
       path('login/', TokenObtainPairView.as_view(),name='token_obtain_pair'),
       path('api/token/', MyObtainTokenPairView.as_view(), name='token_obtain_pair'),
       path('api/token/refresh/', TokenRefreshView.as_view(),name='token_refresh'),
       path('alipay/return/', AlipayView.as_view(),name='alipay'),
       path('index/', TemplateView.as_view(template_name='index.html'),name='index'),
       # path('goods/', GoodsListView.as_view(), name='goods')
       path('', include(router.urls)),
       # path('goods/', goods_list, name='goods')
]

